builder: Autofill scope property of listitemfactory
authorBenjamin Otte <otte@redhat.com>
Tue, 3 Dec 2019 06:37:24 +0000 (07:37 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 30 May 2020 23:26:45 +0000 (19:26 -0400)
I couldn't come up with a better way to automatically inherit the scope
in the builder list item factory that didn't involve a magic
incantation in the XML file. And I do not want developers to know magic
incantations to do a thing that should pretty much always be done.

gtk/gtkbuilder.c

index 5b5a66eb907ce98d86c873de3358d8f90d7a49fa..4be00a4206b6dce1347b3698f22c771d73c0bc8a 100644 (file)
 
 #include "gdkpixbufutilsprivate.h"
 #include "gtkbuildable.h"
+#include "gtkbuilderlistitemfactory.h"
 #include "gtkbuilderscopeprivate.h"
 #include "gtkdebug.h"
 #include "gtkexpression.h"
@@ -707,6 +708,22 @@ gtk_builder_take_bindings (GtkBuilder *builder,
   priv->bindings = g_slist_concat (priv->bindings, bindings);
 }
 
+static void
+ensure_special_construct_parameters (GtkBuilder       *builder,
+                                     GType             object_type,
+                                     ObjectProperties *construct_parameters)
+{
+  GtkBuilderPrivate *priv = gtk_builder_get_instance_private (builder);
+  GValue value = G_VALUE_INIT;
+
+  if (g_type_is_a (object_type, GTK_TYPE_BUILDER_LIST_ITEM_FACTORY))
+    {
+      g_value_init (&value, GTK_TYPE_BUILDER_SCOPE);
+      g_value_set_object (&value, priv->scope);
+      object_properties_add (construct_parameters, "scope", &value);
+    }
+}
+
 GObject *
 _gtk_builder_construct (GtkBuilder  *builder,
                         ObjectInfo  *info,
@@ -804,6 +821,8 @@ _gtk_builder_construct (GtkBuilder  *builder,
     }
   else
     {
+      ensure_special_construct_parameters (builder, info->type, construct_parameters);
+
       obj = g_object_new_with_properties (info->type,
                                           construct_parameters->len,
                                           (const char **) construct_parameters->names->pdata,